<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="form01">
			<p:growl id="messages" />
			<p:panel header="Treatment"
				rendered="#{mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('treatment')}"
				style="text-align:center">
				<p:messages id="message" />
				<p:dataTable id="treatmentRecordTable" widgetVar="treatmentRecord_w"
					style="margin-bottom:20px"
					value="#{giveMedicineControler.treatmentRecordList}"
					var="treatmentRecord" rows="15" paginator="true"
					filteredValue="#{giveMedicineControler.filteredTreatmentRecord}"
					paginatorAlwaysVisible="true" paginatorPosition="bottom"
					first="#{giveMedicineControler.treatmentRecordListFirst}"
					paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Seq']}">
						<h:outputText value="#{treatmentRecord.seq}" />
					</p:column>
					<p:column style="width:10%"
						filterBy="#{treatmentRecord.patientName}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{treatmentRecord.patientName}" />
					</p:column>
					<p:column style="width:10%"
						filterBy="#{treatmentRecord.doctorName}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Doctor']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{treatmentRecord.doctorName}" />
					</p:column>
					<p:column style="width:10%"
						filterBy="#{treatmentRecord.giveMedicineDoctorName}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Medicine Maintainer']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{treatmentRecord.giveMedicineDoctorName}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Date']}">
						<h:outputText value="#{treatmentRecord.treatDate}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
						</h:outputText>
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Status']}">
						<h:outputText
							value="#{dictionaryControler.dictionary[treatmentRecord.statusName]}" />
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['View']} #{dictionaryControler.dictionary['Medicine']}">
						<p:commandButton id="viewButton"
							update=":form01:message,:form04:detailDialog"
							action="#{giveMedicineControler.viewMedicine}"
							icon="ui-icon-search">
							<f:setPropertyActionListener value="#{treatmentRecord}"
								target="#{giveMedicineControler.selectedTreatmentRecord}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Give']} #{dictionaryControler.dictionary['Medicine']}">
						<p:commandButton id="editButton"
							rendered="#{treatmentRecord.canGive}"
							update=":form01:message,:form01:treatmentRecordTable,:form04:detailDialog"
							action="#{giveMedicineControler.startGiveMedicine}"
							icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{treatmentRecord}"
								target="#{giveMedicineControler.selectedTreatmentRecord}" />
							<p:confirm
								header="#{dictionaryControler.dictionary['Confirmation']}"
								message="#{dictionaryControler.dictionary['Are you sure']}?"
								icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
			<h:outputText value="Access Denied, please contact the administrator"
				rendered="#{!(mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('give_medicine'))}"
				style="width:100%; height:50%; text-align:center; font-size:150% !important;position:absolute; margin-left:0; margin-right:0; margin-top:0;margin-bottom:0" />
		</h:form>
	</ui:define>

	<ui:define name="dialog">
		<h:form id="form04">
			<p:dialog id="detailDialog" widgetVar="detailDialog_w" modal="true"
				showEffect="fade" resizable="false" draggable="true"
				closable="false" visible="#{giveMedicineControler.viewOrGiveMode}"
				header="#{dictionaryControler.dictionary['Medicine']}">
				<p:panelGrid columns="4" style="margin-bottom:20px;">
					<p:outputLabel
						value="#{dictionaryControler.dictionary['Treatment']} #{dictionaryControler.dictionary['Seq']}" />
					<h:outputText value="#{giveMedicineControler.selectedTreatmentRecord.seq}" />
					<p:outputLabel
						value="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Name']}" />
					<h:outputText
						value="#{giveMedicineControler.selectedTreatmentRecord.patientName}" />
					<p:outputLabel
						value="#{dictionaryControler.dictionary['Doctor Name']}" />
					<h:outputText
						value="#{giveMedicineControler.selectedTreatmentRecord.doctorName}"
						editable="false" />
					<h:outputText
						value="#{dictionaryControler.dictionary['Treatment Date']}" />
					<h:outputText
						value="#{giveMedicineControler.selectedTreatmentRecord.treatDate}">
						<f:convertDateTime pattern="yyyy-MM-dd hh:mm" timeZone="GMT+8" />
					</h:outputText>
				</p:panelGrid>
				<p:dataTable id="medicineTable_t" widgetVar="medicineTable_t_w"
					style="margin-bottom:20px;width:500px"
					value="#{giveMedicineControler.selectedTreatmentRecord.medicines}"
					var="medicine">
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Medicine']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{medicine.key.name}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Generic Number']}">
						<h:outputText value="#{medicine.key.genericNumber}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Note']}">
						<h:outputText value="#{medicine.key.note}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Quantity']}">
						<h:outputText value="#{medicine.quantity}" />
					</p:column>
				</p:dataTable>
				<p:messages id="msg" />
				<div style="text-align: right">
					<p:commandButton value="#{dictionaryControler.dictionary['Ok']}"
						ajax="true" rendered="#{giveMedicineControler.viewMode}"
						actionListener="#{giveMedicineControler.endViewMeidicine}"
						update="detailDialog" immediate="true" style="margin-right:5px" />
					<p:commandButton value="#{dictionaryControler.dictionary['Give']}"
						ajax="true" rendered="#{giveMedicineControler.giveMode}"
						actionListener="#{giveMedicineControler.giveMedicine}"
						update="detailDialog,:form01:treatmentRecordTable"
						oncomplete="PF('treatmentRecord_w').clearFilters();"
						style="margin-right:5px" />
					<p:commandButton id="cancelBtn" rendered="#{giveMedicineControler.giveMode}"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						actionListener="#{giveMedicineControler.cancelGiveMedicine}"
						update="detailDialog" immediate="true" />
				</div>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>